package com.api.weavernorth.action.sick;

import org.apache.commons.logging.Log;
import weaver.conn.RecordSet;
import weaver.general.Util;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

@Path("/weavernorth/action/sick/Prenatal")
public class Prenatal extends HttpServlet {
    private static Log log = org.apache.commons.logging.LogFactory.getLog(Prenatal.class.getName());
    @GET
    @Path("/getData")
    @Produces(MediaType.TEXT_PLAIN)
    public String getDatas(@Context HttpServletRequest request, @Context HttpServletResponse response) {


        RecordSet rsAll = new RecordSet();
        RecordSet rs = new RecordSet();
        //判断的变量
        String strflag="";

        //存放总时长
        double dubZsc=0;

        //获取前端js传入的请假人姓名和请假类型和时长
        String  strQjrXm=request.getParameter("xm");
        log.info("请假人姓名："+strQjrXm);
        String  strQjlx=request.getParameter("qjlx");
        log.info("请假类型："+strQjlx);
        String  strSc=request.getParameter("sc");
        log.info("时长："+strSc);
        String  strKsrq=request.getParameter("ksrq");
        log.info("开始日期："+strKsrq);

        //请假人姓名转为数组
        String[] strQjrXmSpl = strQjrXm.split(",");
        log.info("请假人姓名转为数组后："+strQjrXmSpl);
        //请假类型转为数组
        String[] strQjlxSpl = strQjlx.split(",");
        log.info("请假类型转为数组后："+strQjlxSpl);
        //时长转为数组
        String[] strScSpl = strSc.split(",");
        log.info("请假时长转为数组后："+strScSpl[1]);
        //开始日期转为数组
        String[] strKsrqSpl = strKsrq.split(",");
        log.info("请假开始日期转为数组后："+strKsrqSpl);



        for(int i = 1;i<strQjrXmSpl.length;i++){


            //查询状态不为保存的流程的对应数据的时长；
            String strSql = " select detail_duration  from  formtable_main_110_dt1 d,workflow_requestbase w ,formtable_main_110 f where f.id=d.mainid  and f.requestid=w.requestid and currentnodetype!=0 and   detail_resourceId ='"+strQjrXmSpl[i]+"' and  detail_newLeaveType ='"+strQjlxSpl[i]+"' and  detail_fromDate='"+strKsrqSpl[i]+"'";
            log.info("查询时长的sql:"+strSql);
            rs.executeQuery(strSql);

            //查询状态不为保存的流程对应的所有时长
            String strSqlAll = " select detail_duration  from  formtable_main_110_dt1 d,workflow_requestbase w ,formtable_main_110 f where f.id=d.mainid  and f.requestid=w.requestid and currentnodetype!=0 and   detail_resourceId ='"+strQjrXmSpl[i]+"' and  detail_newLeaveType ='"+strQjlxSpl[i]+"'";
            log.info("查询所有时长的sql:"+strSqlAll);
            rsAll.executeQuery(strSqlAll);
            //获取所有的请假时长
            while(rsAll.next()){
                String strAllZsc = Util.null2String(rsAll.getString("detail_duration"));
                int intAllZsc=  Integer.parseInt(strAllZsc);
                dubZsc=dubZsc+intAllZsc;
            }
            log.info("此人请过所有的产检假："+dubZsc);
            String strZsc = String.valueOf(dubZsc);

            if(rs.next()){
                strflag="false,"+strZsc;
                return strflag;
            }else{
                strflag="true,"+strZsc;;
                return strflag;
            }
        }
        log.info("flag:"+strflag);

        return strflag;

    }
}